{extend name="public/base" /}
{block name="title"}案例管理{/block}
{block name="main"}

<blockquote class="layui-elem-quote quoteBox e-quoteBox">
    <form class="layui-form" action="" method="GET">        
        <div class="layui-inline">
            <label class="layui-form-label">分类</label>
            <div class="layui-input-inline layui-col-md6" id="JS_select">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-inline layui-col-md6" id="JS_select">
                <select name="status">
                    <option value=""  {$where['status']==''? 'selected': ''}>全部</option>
                    <option value="1" {$where['status']==1? 'selected': ''}>正常</option>
                    <option value="2" {$where['status']==2? 'selected': ''}>关闭</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">搜索</label>
            <div class="layui-input-inline layui-col-md6">
                <input class="layui-input" placeholder="关键词搜索" name="keyword" />
            </div>
        </div>
        <button class="layui-btn search_btn" id="search_btn" lay-submit="" lay-filter="whereSearchBtn">搜索</button>
        <a href="/set/cases/add" class="layui-btn layui-btn-normal">添加案例</a>
    </form>
</blockquote>
 
<table id="tableList" lay-filter="tableList"></table>



<script type="text/html" id="Tb_img">
    <img  src="{{d.pic}}"/>
</script>

<script type="text/html" id="Tb_status">
    <input lay-filter="status" type="checkbox" {{d.status ==1? 'checked': ''}} data-id="{{d.id}}" lay-skin="switch" lay-text="正常|关闭">
</script>

<script type="text/html" id="Tb_addtime">
    {{ layui.common.data('yyyy-m-d H:i:s',d.addtime) }}
</script>

<script type="text/html" id="Tb_operation">
    <div class="layui-btn-group">         
        <a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-sm" data-id="{{d.id}}"  lay-event="del">删除</a>
        <a href="/set/cases/edit/id/{{d.id}}" class="layui-btn layui-btn-sm" lay-event="update">编辑</a>
    </div>
</script>
{/block}
{block name="script"}
<script>

layui.use(['form','listTable','selectTree'], function (form){  
    
    var group = {:json_encode($grouplist)};
    // 分类显示
    var showSelect = function(data){
        var select = layui.selectTree.render({
            elem : '#JS_select', //绑定的容器元素
            data : data, //展示的数据 和 url 赋值其中一个 data 优先 没有的话从接口获取数据
          //  url  : '/set/casesgroup/ajaxlist'
          //  checkid : 25, // 数据选中的ID
            name : 'groupid', // 生成的表单名称
            field : {
                id      : 'id',     // 上传表单的值对应的字段
                name    : 'groupname',   // 显示的名称
                depth   : 'depth'   // 级别字段
            }        
        });
    }
    showSelect(group);
    
    var init = layui.listTable.render({
        search:'#search_btn',
        url : '/set/cases/index', //数据接口
        urledit : '/set/cases/editstatus',//更新状态
        urldel : '/set/cases/del',//删除数据
        cols: [[
          {field: 'id', title: 'ID', width:60, fixed: 'left'},          
         // {field: 'pic', title: '案例图片', width:120,templet: '#Tb_img'}, 
          {field: 'pic', title: '案例图片', width:120,templet: function(d){return init.tool.img(d.pic)}}, 
          {field: 'name', title: '案例名称', width:160},                  
          {field: 'des', title: '简介'} ,
          {field: 'groupname', title: '分类', width:120},
          {field: 'addtime', title: '添加时间', width:170,templet: function(d){
             return init.tool.date('yyyy-mm-dd HH:ii:ss',d.addtime) }},
          {field: 'status', title: '状态', width: 100,templet: function(d){return init.tool.status(d.status,d.id)}},
          {field: 'operation', title: '操作', width: 130,templet: '#Tb_operation' ,fixed: 'right'} // 80 130 180
        ]],        
    });    
});
</script>
{/block}